<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>


</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" >
            <div class="layui-form-item">
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-block">
                    <input name="userName" lay-verify="title" class="layui-input" placeholder="请输入姓名">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号：</label>
                <div class="layui-input-block">
                    <input name="phone" lay-verify="title" class="layui-input" placeholder="请输入手机号">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">组织：</label>
                <div class="layui-input-block">
                    <input name="phone" lay-verify="title" class="layui-input" placeholder="请输入手机号">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">组织：</label>
                <div class="layui-input-block">
                    <select>
                        <option value="北京">北京</option>
                        <option value="上海">上海</option>
                        <option value="广州">广州</option>
                        <option value="深圳">深圳</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">动态下拉</label>
                <div class="layui-input-block">
                    <select name="code" id="OpSelect" lay-verify="required">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色：</label>
                <div class="layui-input-block">
                    <select>
                        <option value="北京">北京</option>
                        <option value="上海">上海</option>
                        <option value="广州">广州</option>
                        <option value="深圳">深圳</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="demo1">新增</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form'], function () {
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log(data.field);
            //ajax 调用接口
            $.post("/userInfo/addUserInfo",data.field,function(res){
                if(res.code==0){
                    //新增成功
                    layer.msg("新增成功");
                    location.href = "UserInfoList.html";
                }else{
                    //新增失败
                    layer.msg('新增失败！');
                }
            });
            return false;
        });
    });
    var selectApi= "/dictInfo/dictTreeList";//TODO:下拉数据api
    $.ajax({
        type: "POST",
        url:selectApi,
        datatype: "json",
        success: function (data) {
           console.log("树结构 "+ JSON.stringify(data.data))
            $.each(data, function (index, item) {
                $('#OpSelect').append(new Option(item.dictId, item.dictName));// 下拉菜单里添加元素
            });
            layui.form.render('select');
        }, error: function () {
            console.log('error')
        }
    });
</script>
</body>
</html>